package com.tul.exercise.base.java8.stream.base;

import com.tul.exercise.base.java8.common.Constant;
import com.tul.exercise.base.java8.util.BeanAtributeHelper;
import com.tul.exercise.base.utils.MathUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ClassName Dish
 * @Description 菜品类
 * @Author tul 2018/12/22
 * @Version 1.0
 **/
public class Dish {
    private  String name;
    private  boolean  vegetarian;
    private  int calories;
    private  Type type;

    public Dish() {

    }

    public Dish(String name, boolean vegetarian, int calories, Type type) {
        this.name = name;
        this.vegetarian = vegetarian;
        this.calories = calories;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public boolean isVegetarian() {
        return vegetarian;
    }

    public int getCalories() {
        return calories;
    }

    public Type getType() {
        return type;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setVegetarian(boolean vegetarian) {
        this.vegetarian = vegetarian;
    }

    public void setCalories(int calories) {
        this.calories = calories;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public  enum Type{
        MEAT, FISH, OTHER,VEGTABLE
    }

    @Override
    public String toString(){
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }

    public static Dish createDish() {
        Dish result = new Dish();
        result.setName(BeanAtributeHelper.getRandomItem(Constant.DISH_NAMES));
        result.setType(BeanAtributeHelper.getRandomItem(Stream.of(Type.MEAT, Type.FISH,
                Type.OTHER, Type.VEGTABLE)
                .collect(Collectors.toList())));

        result.setCalories(MathUtils.getRandomInt(0, 1000));
        result.setVegetarian(result.getType()==Type.VEGTABLE);
        return result;
    }

    public static List<Dish> createDishs(int num) {
        List<Dish> results = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            results.add(createDish());
        }
        return results;
    }

}
